//
//  UIColor+Additions.m
//  OCStarterProject
//
//  Created by huaya on 2025/10/2.
//

#import "UIColor+Additions.h"

@implementation UIColor (Additions)

+ (UIColor *)colorWithHexString:(NSString *)hexString {
    NSString *colorString = [[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] uppercaseString];
    CGFloat alpha, red, blue, green;
    
    switch ([colorString length]) {
        case 3: // #RGB
            alpha = 1.0f;
            red   = [self colorComponentFrom:colorString start:0 length:1];
            green = [self colorComponentFrom:colorString start:1 length:1];
            blue  = [self colorComponentFrom:colorString start:2 length:1];
            break;
        case 4: // #ARGB
            alpha = [self colorComponentFrom:colorString start:0 length:1];
            red   = [self colorComponentFrom:colorString start:1 length:1];
            green = [self colorComponentFrom:colorString start:2 length:1];
            blue  = [self colorComponentFrom:colorString start:3 length:1];
            break;
        case 6: // #RRGGBB
            alpha = 1.0f;
            red   = [self colorComponentFrom:colorString start:0 length:2];
            green = [self colorComponentFrom:colorString start:2 length:2];
            blue  = [self colorComponentFrom:colorString start:4 length:2];
            break;
        case 8: // #AARRGGBB
            alpha = [self colorComponentFrom:colorString start:0 length:2];
            red   = [self colorComponentFrom:colorString start:2 length:2];
            green = [self colorComponentFrom:colorString start:4 length:2];
            blue  = [self colorComponentFrom:colorString start:6 length:2];
            break;
        default:
            return nil;
    }
    
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}

+ (CGFloat)colorComponentFrom:(NSString *)string start:(NSUInteger)start length:(NSUInteger)length {
    NSString *substring = [string substringWithRange:NSMakeRange(start, length)];
    NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat:@"%@%@", substring, substring];
    unsigned hexComponent;
    [[NSScanner scannerWithString:fullHex] scanHexInt:&hexComponent];
    return hexComponent / 255.0f;
}

+ (UIColor *)randomColor {
    CGFloat hue = (arc4random() % 256 / 256.0);
    CGFloat saturation = (arc4random() % 128 / 256.0) + 0.5;
    CGFloat brightness = (arc4random() % 128 / 256.0) + 0.5;
    return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
}

+ (UIColor *)themeColor {
    return [UIColor mk_colorWithR:158 G:109 B:252];
}
+ (UIColor *)secondaryColor {
    return [UIColor colorWithHexString:@"#5856D6"];
}

+ (UIColor *)backgroundColor {
    return [UIColor colorWithHexString:@"#F2F2F7"];
}

+ (UIColor *)textColor {
    return [UIColor colorWithHexString:@"#000000"];
}

+ (UIColor *)lightTextColor {
    return [UIColor colorWithHexString:@"#8E8E93"];
}

+ (UIColor *)gradientStartColor {
    return [UIColor colorWithHexString:@"#667eea"];
}

+ (UIColor *)gradientEndColor {
    return [UIColor colorWithHexString:@"#764ba2"];
}


+ (UIColor *)hex_2AC3AB{
    return MK_COLOR_HEX(0x2AC3AB);
}

+ (UIColor *)hex_2AC3AB_alpha:(CGFloat)alpha{
    return MK_COLOR_HEXA(0x2AC3AB, alpha);
}

+ (UIColor *)hex_FF7536{
    return MK_COLOR_HEX(0xFF7536);
}

+ (UIColor *)hex_FB7245{
    return MK_COLOR_HEX(0xFB7245);
}

+ (UIColor *)hex_1BC0B0{
    return MK_COLOR_HEX(0x1BC0B0);
}

+ (UIColor *)hex_B3D465{
    return MK_COLOR_HEX(0xB3D465);
}



+ (UIColor *)hex_F33131{
    return MK_COLOR_HEX(0xF33131);
}

+ (UIColor *)hex_EF7139{
    return MK_COLOR_HEX(0xEF7139);
//    return MK_COLOR_RGB(245, 59, 19);
}

+ (UIColor *)bgScreen{
    return MK_COLOR_RGB(248, 248, 248); //0xF5F5F9
}

+ (UIColor *)bgNaviView{
    return MK_COLOR_RGB(249, 249, 249);
}

+ (UIColor *)hex_1E1E1E{
    return MK_COLOR_HEX(0x1E1E1E);
}

+ (UIColor *)hex_EFEFEF{
    return MK_COLOR_HEX(0xEFEFEF);
}

+ (UIColor *)hex_F7F7F7{
    return MK_COLOR_HEX(0xF7F7F7);
}

+ (UIColor *)bgBtnGray{
    return MK_COLOR_HEX(0xF7F7F7);
}

+ (UIColor *)hex_333333{
    return MK_COLOR_HEX(0x333333);
}

+ (UIColor *)hex_666666{
    return MK_COLOR_HEX(0x666666);
}

+ (UIColor *)hex_888888{
    return MK_COLOR_HEX(0x888888);
}

+ (UIColor *)hex_B8B8B8{
    return MK_COLOR_HEX(0xB8B8B8);
}

+ (UIColor *)hex_89C997{
    return MK_COLOR_HEX(0x89C997);
}

+ (UIColor *)hex_BC6F00{
    return MK_COLOR_HEX(0xBC6F00);
}


+ (UIColor *)hex_C6C6C6{
    return MK_COLOR_HEX(0xC6C6C6);
}

+ (UIColor *)hex_E5E5E5{
    return MK_COLOR_HEX(0xE5E5E5);
}

+ (UIColor *)hex_E5E5E5_border{
    return MK_COLOR_HEX(0xE5E5E5);
}
+ (UIColor *)hex_F6F6F6{
    return MK_COLOR_HEX(0xF6F6F6);
}
+ (UIColor *)hex_F3F3F3{
    return MK_COLOR_HEX(0xF3F3F3);
}

+ (UIColor *)shadow{
    return MK_COLOR_RGBA(0, 0, 0, 0.5);
}

+ (UIColor *)darkShadow{
    return MK_COLOR_RGBA(0, 0, 0, 0.7);
}


+ (UIColor *)buttonSelected{
    return MK_COLOR_RGBA(0, 0, 0, 0.1);
}


+ (UIColor *)hex_999999{
    return [UIColor colorWithHexString:@"999999"];
}
+ (UIColor *)hex_ECECEC{
    return [UIColor colorWithHexString:@"#ECECEC"];
}
+ (UIColor *)hex_9E6DFC{
    return [UIColor colorWithHexString:@"9E6DFC"];
}
+ (UIColor *)hex_F5F3FF{
    return [UIColor colorWithHexString:@"F5F3FF"];
}
+ (UIColor *)hex_DCDCDC{
    return [UIColor colorWithHexString:@"DCDCDC"];
}
+ (UIColor *)hex_F8F8F8{
    return [UIColor colorWithHexString:@"F8F8F8"];
}

+ (UIColor *)hex_191820{
    return [UIColor colorWithHexString:@"191820"];
}
+ (UIColor *)hex_F2F2F2{
    return [UIColor colorWithHexString:@"F2F2F2"];
}
+ (UIColor *)hex_313538{
    return [UIColor colorWithHexString:@"313538"];
}
+ (UIColor *)hex_F5F5F5{
    return [UIColor colorWithHexString:@"F5F5F5"];
}
+ (UIColor *)hex_EEEEEE{
    return [UIColor colorWithHexString:@"EEEEEE"];
}
+ (UIColor *)hex_F6F6FE{
    return [UIColor colorWithHexString:@"F6F6FE"];
}


@end
